@extends('backstage.layout.master')
@section('title', '订货单详情')
@section('style')
    <!-- page specific plugin styles -->
    <link rel="stylesheet" href="backstage/assets/css/jquery-ui-1.10.3.custom.min.css"/>
    <link rel="stylesheet" href="backstage/assets/css/chosen.css"/>
    <link rel="stylesheet" href="backstage/assets/css/colorpicker.css"/>
    <!-- fonts -->
    <style>
        .ace-file-input input[type=file] {
            position: static;
        }

        .ace-nav {
            height: 10px;
        }
        .ui-datepicker {
            width: 18em;
        }
        .ui-datepicker{
            width: 15em;
            padding-left: 1em;
        }
        .navbar {
            margin-bottom: 3px;
        }
        #add_temp{
            margin-left: 10px;
            color: #0a03ff;
        }
    </style>
@stop
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>
        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home" target="_blank">主页</a>
            </li>
            <li class="active">
                <a target="_blank" href="/backstage/purchase-order/purchase-order-list">订货单列表</a>
            </li>
            <li>
                订货单详情
            </li>
        </ul><!-- .breadcrumb -->
    </div>
    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="page-header">
                    <h1>
                        订货单列表
                        <small>
                            <i class="icon-double-angle-right"></i>
                            订货单详情
                        </small>
                        <span class="pull-right">
                          <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/purchase-order/purchase-order-list';">订货单列表</button>
                         </span>
                    </h1>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="tabbable">
                            <form id="form" class="form-horizontal">
                                <div class="tab-content no-border padding-24">
                                    <div id="faq-tab-1" class="tab-pane fade in active">
                                        <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                                            <tr>
                                                <td colspan="6" style="color: #2709ff;font-weight:bold;text-align:center">订货单</td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    编号：
                                                </td>
                                                <td >
                                                    <input name="purchase_order_id" id="purchase_order_id" value="{{isset($purchase_order->purchase_order_id)?$purchase_order->purchase_order_id:''}}" type="text" readonly>
                                                </td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    供货商：
                                                </td>
                                                <td colspan="1" >
                                                 {{isset($purchase_order->supplier_name)?$purchase_order->supplier_name:''}}
                                                </td>
                                                <td>供货商编号：</td>
                                                <td colspan="3">
                                                    {{isset($purchase_order->supplier_id)?$purchase_order->supplier_id:''}}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    实际支付总金额：
                                                </td>
                                                <td colspan="1" >
                                                    ¥{{isset($purchase_order->actual_fee)?$purchase_order->actual_fee:''}}
                                                </td>
                                                <td>订单状态：</td>
                                                <td colspan="3">
                                                    @if(($purchase_order->purchase_order_status!=1)&&($purchase_order->purchase_order_status!=2)&&($purchase_order->purchase_order_status!=3)&&($purchase_order->purchase_order_status!=4))
                                                        未知错误
                                                    @elseif($purchase_order->purchase_order_status==4)
                                                        已入库
                                                    @else
                                                        <select id="purchase_order_status_{{$purchase_order->purchase_order_id}}" onchange="changePurchaseOrderStatus('{{$purchase_order->purchase_order_id}}')">
                                                            <option @if($purchase_order->purchase_order_status==1) selected @endif value =1 >未下单</option>
                                                            <option @if($purchase_order->purchase_order_status==2) selected @endif value =2 >已下单</option>
                                                            <option @if($purchase_order->purchase_order_status==3) selected @endif value =3 >在途</option>
                                                            <option @if($purchase_order->purchase_order_status==4) selected @endif value =4 >已入库</option>
                                                        </select>
                                                    @endif
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    运费：
                                                </td>
                                                <td >
                                                    {{isset($purchase_order->postage)?$purchase_order->postage:''}}
                                                </td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    快递公司：
                                                </td>
                                                <td colspan="1" >
                                                    <select id="express_id"  name="express_id" class="col-sm-2" style="width: 75%">
                                                        <option value=0>请选择....</option>
                                                        @if(isset($express_list)&&!empty($express_list))
                                                            @foreach($express_list as $express)
                                                                <option @if($express->express_id==$purchase_order->express_id ) selected @endif value="{{isset($express->express_id)?$express->express_id:''}}">{{isset($express->express_name)?$express->express_name:''}}</option>
                                                            @endforeach
                                                        @endif
                                                    </select>
                                                </td>
                                                <td>快递单号：</td>
                                                <td colspan="3">
                                                    @if($purchase_order->purchase_order_status==4)
                                                        {{isset($purchase_order->order_express_id)?$purchase_order->order_express_id:''}}
                                                    @else
                                                    <input type="text"  name="order_express_id" id="order_express_id" value="{{isset($purchase_order->order_express_id)?$purchase_order->order_express_id:''}}">
                                                    <input type="button" value="修改" id="update_order_express_id" style="color: #0a03ff">
                                                    @endif
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="6" >备注:
                                                    <textarea  name="remark" readonly style="width: 85%;margin-left: 5%">{{isset($purchase_order->remark)?$purchase_order->remark:''}}</textarea>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="6" style="color: red;font-weight:bold;text-align: center">订货明细</td>
                                            </tr>
                                            <tr id="purchase_order_detail_list">
                                                <td>sku</td>
                                                <td>
                                                品牌|模板名|颜色|尺码名|
                                                </td>
                                                <td>单价</td>
                                                <td>采购数量</td>
                                                <td>支付金额</td>
                                            </tr>
                                            @foreach($purchase_order_details as $detail)
                                               <tr>
                                                <td>{{isset($detail->sku)?$detail->sku:''}}</td>
                                                <td>
                                                    {{isset($detail->brand_name)?$detail->brand_name:''}}|
                                                    {{isset($detail->temp_name)?$detail->temp_name:''}}|
                                                    {{isset($detail->colour_name)?$detail->colour_name:''}}|
                                                    {{isset($detail->size_name)?$detail->size_name:''}}
                                                </td>
                                                <td>{{isset($detail->price)?$detail->price:''}}</td>
                                                <td>{{isset($detail->num)?$detail->num:''}}</td>
                                                <td>{{isset($detail->actual_fee)?$detail->actual_fee:''}}</td>
                                              </tr>
                                            @endforeach
                                        </table>
                                    </div>
                                </div>
                            </form>
                            <!-- PAGE CONTENT ENDS -->
                        </div><!-- /.col -->
                    </div><!-- /.row -->
                </div><!-- /.page-content -->
                @stop
@section('script')
<script type="text/javascript">
   _token = '{{csrf_token()}}';
   $(function(){
       $('#update_order_express_id').click(function() {
           var express_id=$('#express_id option:selected').val();
           var order_express_id=$('#order_express_id').val();
           var purchase_order_id=$('#purchase_order_id').val();
           purchase_order_id=parseInt(purchase_order_id);
           $.ajax({
               type: "POST",
               cache: true,
               url: "/backstage/purchase-order/update-express",
               data:{
                   'express_id':express_id,
                   'purchase_order_id':purchase_order_id,
                   'order_express_id':order_express_id,
               }, success: function (msg) {
                   if(msg.state==1){
                       swal({title: '添加成功！', text: "",type: "success", timer:500 });
                   }else {
                       swal({title: msg.message, text: "",type: "error", timer:1000 });
                   }
               }, error: function () {
                   swal({title: "系统繁忙！", text: "",type: "error", timer:1000 })
               }
           });
       });
   });
   function changePurchaseOrderStatus(id) {
       var purchase_order_status_id='purchase_order_status_'+id;
       var purchase_order_status=parseInt($('#'+purchase_order_status_id+' option:selected').val());
       if(purchase_order_status==0){
           swal({title: "状态未知错误！", text: "",type: "error", timer:500 });
           return;
       }
       $.ajax({
           type: "POST",
           cache: true,
           url: "/backstage/purchase-order/update-status",
           data:{'id':id,'purchase_order_status':purchase_order_status},
           success: function (msg) {
               if(msg.state==1){
                   swal({title: "更新成功！", text: "",type: "success", timer:1000 });
                   if(purchase_order_status==1){
                       window.location.href="/backstage/purchase-order/update-purchase-order?id="+id;
                   }
               }else {
                   swal({title: msg.message, text: "",type: "error", timer:1000 });
               }
           }, error: function () {
               swal({title: "系统繁忙！", text: "",type: "error", timer:1000 });
           }
       });
   }
</script>
@stop